#ifdef GL_ES
precision highp float;
#endif

varying vec3 vNormal;
varying vec3 vPos;

uniform vec3 uCamPos;

//1 dir light
uniform vec3 uLDir;
uniform vec4 uLAmbient;
uniform vec4 uLDiffuse;
uniform vec4 uLSpecular;

//material
uniform vec4 uMAmbient;
uniform vec4 uMDiffuse;
uniform vec4 uMSpecular;
uniform float uMSpecPow;

void main(void) {
	vec3 norm = normalize(vNormal);
	vec3 lDir = normalize(uLDir);
	vec3 toEye= -normalize(uCamPos - vPos);

	//compute diffuse
	vec4 diffuse = max(dot(norm, -lDir), 0.0) * (uMDiffuse * uLDiffuse);
	
	//compute specular
	vec3 r = reflect(lDir, norm);
	vec4 specular = pow(max(dot(toEye, r), 0.0), uMSpecPow) * (uMSpecular * uLSpecular);

	gl_FragColor = (uMAmbient * uLAmbient) + diffuse + specular;
}